#!/usr/bin/python
# 2001:dc7:1000::0/48 -> 2001:dc7:1000:0000::0/64 ~ 2001:dc7:1000:ffff::0/64
import sys
import getopt

def usage():
    print '''
    spilt.py -a x.x.x.x -v 4/6 -o 16 -s 24
    '''

def ipv4(a=None, o=None, s=None):
    if a and o and s:
        bl = map(bin, a.split('.'))
    else:
        print('Address, orinet, subnet should be defined.')

if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'ha:v:o:s:', 
                            ['help', 'address=', 'version=', 'orinet=', 'subnet='])
       #print(opts)
       #print(args)
       for o, a in opts:
           if o in ('-h', '--help'):
               usage()
               sys.exit()
            if o in ('-a', '--address'):
                address = a
            if o in ('-v', '--version'):
                version = a
            if o in ('-o', '--orinet'):
                orinet = a
            if o in ('-s', '--version'):
                subnet = a
        if version == '4':
            ipv4(a=address, o=orinet, s=subnet)
        else:
            ipv6(a=address, o=orinet, s=subnet)
    except getopt.GetoptError as e:
        usage()
        sys.exit()